package com.loukou.lkt.api.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.loukou.lkt.lkt.entity.Goods;
import com.loukou.lkt.lkt.req.WebGoodsReq;
import com.loukou.lkt.lkt.resp.RespDto;
import com.loukou.lkt.lkt.service.GoodsService;

@Controller
@RequestMapping("/api/goods")
public class GoodsController {
	
	@Autowired
	private GoodsService goodsService;
	
	@RequestMapping(value="/receiveWebGoods", method=RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
	@ResponseBody
	public RespDto<String> receiveWebGoods(@RequestBody List<WebGoodsReq> webGoodsList){
		RespDto<String> resp = new RespDto<String>();
		if(webGoodsList == null || webGoodsList.size() == 0){
			resp.setCode(401);
			resp.setMsg("参数错误");
			return resp;
		}
		List<Goods> goodsList = new ArrayList<Goods>();
		for(WebGoodsReq goodsReq: webGoodsList){
			Goods goods = new Goods();
			BeanUtils.copyProperties(goodsReq, goods);
			goodsList.add(goods);
		}
		goodsService.saveGoodsList(goodsList);
		return resp;
	}
	

	
	

}
